﻿Namespace EIBData.DPT
    Public NotInheritable Class EIBDataDPT_6_020
        Inherits EIBDataDPT_6_Base

        Public Enum EIBDataDPT_6_020_Mode
            Mode0 = &H1
            Mode1 = &H2
            Mode2 = &H4
        End Enum

        Private _StateA As Boolean = Nothing
        Private _StateB As Boolean = Nothing
        Private _StateC As Boolean = Nothing
        Private _StateD As Boolean = Nothing
        Private _StateE As Boolean = Nothing
        Private _Mode As EIBDataDPT_6_020_Mode = Nothing

        Sub New(data As Byte())
            MyBase.New(data)

            _StateA = (_value And &H80) >> 7
            _StateB = (_value And &H40) >> 6
            _StateC = (_value And &H20) >> 5
            _StateD = (_value And &H10) >> 4
            _StateE = (_value And &H8) >> 3
            _Mode = _value And &H7
        End Sub

        Sub New(stateA As Boolean, stateB As Boolean, stateC As Boolean, stateD As Boolean, stateE As Boolean, mode As EIBDataDPT_6_020_Mode)
            MyBase.New(If(stateA, 1, 0) << 7 + If(stateB, 1, 0) << 6 + If(stateC, 1, 0) << 5 + If(stateD, 1, 0) << 4 + If(stateE, 1, 0) << 3 + mode)

            If Not [Enum].IsDefined(GetType(EIBDataDPT_6_020_Mode), mode) Then Throw New EIB.Exceptions.EIBDataEncodeException("")
        End Sub


        Public Overrides Function ToInfoList() As List(Of EIB.InfoBase)
            Dim list As New List(Of EIB.InfoBase)

            list.Add(New EIB.Info("Type", DPT_Name))
            list.Add(New EIB.Info("A", _StateA))
            list.Add(New EIB.Info("B", _StateB))
            list.Add(New EIB.Info("C", _StateC))
            list.Add(New EIB.Info("D", _StateD))
            list.Add(New EIB.Info("E", _StateE))
            list.Add(New EIB.Info("Mode", String.Format("{0} (0x{0:X})", _Mode)))

            Return list
        End Function

        Public Shared Shadows ReadOnly Property DPT_Name As String
            Get
                Return "DPT_Status_Mode3"
            End Get
        End Property

        Public Shared Shadows ReadOnly Property DPT_Number As String
            Get
                Return "6.020"
            End Get
        End Property

        Public Overrides Function ToString() As String
            Return String.Format("A: {0}, B: {1}, C: {2}, D: {3}, E: {4}, Mode: {5}", _StateA, _StateB, _StateC, _StateD, _StateE, _Mode)
        End Function
    End Class
End Namespace